package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.base.BaseController;
import com.atguigu.entity.HouseUser;
import com.atguigu.service.HouseUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @ClassName HouseUserController
 * @Description 此类描述:
 * @Author dangchen
 * @DateTime 2022-08-25 15:30
 * @Version 1.0
 */
@RequestMapping("/houseUser")
@Controller
public class HouseUserController extends BaseController {
    @Reference
    private HouseUserService houseUserService;

    @RequestMapping("create")
    public String create(Model model, @RequestParam long houseId){
        model.addAttribute("houseId",houseId);
        return "houseUser/create";
    }

    @RequestMapping("save")
    public String save(HouseUser houseUser){
        houseUserService.insert(houseUser);
        return "common/successPage";
    }

    @RequestMapping("edit/{id}")
    public String edit(Model model, @PathVariable Long id){
        HouseUser houseUser = houseUserService.getById(id);
        model.addAttribute("houseUser",houseUser);
        return "houseUser/edit";
    }

    @RequestMapping("update")
    public String update(HouseUser houseUser){
        houseUserService.update(houseUser);
        return "common/successPage";
    }

    @RequestMapping("delete/{houseId}/{id}")
    public String delete(@PathVariable long houseId,@PathVariable long id){
        houseUserService.delete(id);
        return "redirect:/house/" + houseId;
    }
}
